﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace bd2wpf
{
    /// <summary>
    /// Логика взаимодействия для Add.xaml
    /// </summary>
    public partial class Add : Window
    {
        
        private MainWindow parent;
        public Add()
        {
            InitializeComponent();
        }

        public void setparent(MainWindow link)//функция получающая ссылку на родителя
        {
            parent = link;
        }

        private void Cansel_Click(object sender, RoutedEventArgs e)//Отмена добавления
        {
            this.Close();
        }

        private void Add2DB_Click(object sender, RoutedEventArgs e)
        {
            //Заменяем Null на пустую строку, иначе ошибка
            if (name.Text == null) { name.Text = ""; }
            if (LastName.Text == null) { LastName.Text = ""; }
            if (Patronymic.Text == null) { Patronymic.Text = ""; }
            if (Mobily.Text == null) { Mobily.Text = ""; }
            if (Internal.Text == null) { Internal.Text = ""; }
            if (EMail.Text == null) { EMail.Text = ""; }
            if (Photo.Text == null) { Photo.Text = ""; }
            if (City.Text == null) { City.Text = ""; }
            if (Street.Text == null) { Street.Text = ""; }
            if (Home.Text == null) { Home.Text = ""; }
            if (Flat.Text == null) { Flat.Text = ""; }
            if (Position.Text == null) { Position.Text = ""; }
            if (Subdivision.Text == null) { Subdivision.Text = ""; }
            if (Info.Text == null) { Info.Text = ""; }

            int n = MainWindow.dataSourceMyClass.myClasses.Count;

            MainWindow.dataSourceMyClass.myClasses.Add(new MainWindow.MyClass(name.Text, LastName.Text, Patronymic.Text, Sex.Text,
                        Mobily.Text, Internal.Text, EMail.Text, Photo.Text, City.Text,
                        Street.Text, Home.Text, Flat.Text, Position.Text, Subdivision.Text, Info.Text));//Записываем данные из текстбоксов в запись
 
            parent.dataGrid1.Items.Refresh();//обновляем БД
            this.Close();//Закрыть окно
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

       

     
    }
}
